package com.itheima.controller;

import com.itheima.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class Controller01 {
    @RequestMapping("/add")
    public String addUser(/*@Validated User user, Errors errors, Model model*/){

      /*  if (errors.hasErrors()){
            List<FieldError> fieldErrors = errors.getFieldErrors();

            for (FieldError error : fieldErrors) {
                String fieldName = error.getField();

                System.out.println("fieldName = " + fieldName);

                String message = "<font color='red'>" + error.getDefaultMessage() + "</font>";
                model.addAttribute(fieldName,message);
                System.out.println("error.getDefaultMessage() = " + error.getDefaultMessage());
            }
            return "index";
        }*/
        return "success";

    }
}
